package java8_16;

import java.util.Scanner;

public class Chihuo {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        //菜单，
        String[] cai = {"鱼香肉丝", "火锅", "自助餐"};     //菜名
        double[] cai1 = new double[]{30.0, 20.0, 5.0};//单价
        int[] zan = new int[]{0, 0, 0}; //点赞
        //
        String[] c = new String[4]; //姓名
        int[] c2 = new int[4];  //订购份数
        int[] c3 = new int[4];   //订购时间
        String[] c4 = new String[4];   //地址
        double[] c5 = new double[4];  //总金额
        int[] c6 = new int[4];   //签收状态
        //
        int a;
        boolean a1 = false;
        do {
            System.out.println();
            System.out.println("欢迎使用\"吃货联盟订餐系统\"");
            System.out.println("**********************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("**********************************");
            System.out.print("请选择:");
            a = input.nextInt();
            switch (a) {
                case 1:
                    System.out.println("        我要订餐         ");
                    for (int c1 = 0; c1 < c.length; c1++) {
                        if (c[c1] == null) {
                            System.out.print("请输入订餐人姓名：");
                            String n = input.next();
                            System.out.println("序号" + "\t" + "菜名" + "\t" + "单价\t点赞");
                            for (int caiming = 0; caiming < cai.length; caiming++) {
                                System.out.println((caiming + 1) + "." + cai[caiming] + "\t" + cai1[caiming] + "元\t" + zan[caiming]);
                            }
                            System.out.print("请选择您要点的菜品编号：");
                            int x = input.nextInt();
                            while (x > 3 || x < 0) {
                                System.out.print("您输入的菜品编号有误：");
                                x = input.nextInt();
                            }
                            System.out.print("请输入您需要的份数：");
                            int x1 = input.nextInt();                  //购买份数
                            String cai2 = cai[x - 1] + " " + x1 + "份";
                            double cai3 = cai1[x - 1] * x1;            //价钱
                            int cai4 = (cai3 >= 50) ? 0 : 6;           //送餐费
                            System.out.print("请输入送餐时间：");
                            int x2 = input.nextInt();                   //送餐时间
                            while (x2 < 10 || x2 > 20) {
                                System.out.print("您输入的时间有误：");
                                x2 = input.nextInt();
                            }
                            System.out.print("请输入送餐地址：");
                            String x3 = input.next();

                            System.out.println("订购成功！");
                            System.out.println("您订购的是：" + cai2);
                            System.out.println("送餐时间是（送餐时间是10点至20点间整点送餐）：" + x2 + "点");
                            System.out.println("餐费是：" + cai3 + "元,送餐费：" + cai4 + "元，" + "总价是：" + (cai3 + cai4) + "元");

                            //赋值
                            c[c1] = n;
                            c2[c1] = x1;
                            c3[c1] = x2;
                            c4[c1] = x3;
                            c5[c1] = cai3 + cai4;

                            break;

                        }
                    }
                    break;
                case 2:
                    System.out.println("       查看餐袋     ");
                    System.out.println("序号\t订餐人\t餐品信息\t送餐日期\t送餐地址\t总金额\t签收状态");
                    for (int m = 0; m < c.length; m++) {

                        if (c[m] != null) {
                            System.out.println(" " + (m + 1) + "\t" + c[m] + "\t" + c2[m] + "份  " + cai[m] + "\t" + c3[m] + " \t" + c4[m] + "\t" + c5[m] + "\t" + c6[m]);
                        }
                    }
                    break;
                case 3:
                    System.out.println("\t签收订单");
                    System.out.println("请输入需要签收的订单！");
                    int qianshou = input.nextInt();
                    while (qianshou < 1 || qianshou > 3) {
                        System.out.println("输入订单号有误！请重新输入！");
                        qianshou = input.nextInt();
                    }
                    int qw = 0;
                    for (int x1 = 0; x1 < c.length; x1++) {
                        if (c[x1] != null && c6[x1] == 0) {
                            c6[x1] = 1;
                            qw = 1;
                            break;
                        } else if (c[x1] != null && c6[x1] == 1) {
                            qw = 2;
                        }
                    }
                    if (qw == 1) {
                        System.out.println("订单签收！");
                    } else if (qw == 2) {
                        System.out.println("订单不能重复签收！");
                    } else {
                        System.out.println("没有该订单！");
                    }
                    break;
                case 4:
                    System.out.println("\t删除订单！");
                    System.out.println("请输入需要删除的订单！");
                    int p = input.nextInt();
                    for (int x1 = 0; x1 < c.length; x1++) {
                        if (c[x1] != null && c6[x1] == 0 && x1 == p - 1) {
                            System.out.println("未签收不能删除订单！");
                        } else if (c[x1] != null && c6[x1] > 0 && x1 == p - 1) {
                            System.out.println("可以删除！正在删除！");
                            for (int o = p; o < c.length - 1; o++) {
                                c[o] = c[o + 1];
                                c2[o] = c2[o + 1];
                                c3[o] = c3[o + 1];
                                c4[o] = c4[o + 1];
                                c5[o] = c5[o + 1];
                                c6[o] = c6[o + 1];
                            }
                            c[c.length - 1] = null;
                            c2[c.length - 1] = 0;
                            c3[c.length - 1] = 0;
                            c4[c.length - 1] = null;
                            c5[c.length - 1] = 0.0;
                            c6[c.length - 1] = 0;
                            break;
                        } else {
                            System.out.println("订单不存在！");
                        }
                    }
                case 5:
                    System.out.println("\t点赞!");
                    System.out.println("请输入需要点赞的菜品编号！");
                    System.out.println("序号" + "\t" + "菜名");
                    for (int caiming = 0; caiming < cai.length; caiming++) {
                        System.out.println((caiming + 1) + "." + cai[caiming]);
                    }
                    int m = input.nextInt();
                    while (m > 3 || m < 1) {
                        System.out.println("没有该菜品！请重新输入！");
                        m = input.nextInt();
                    }
                    zan[m - 1]++;
                    break;
                case 6:
                    a = 1;
                    a1 = true;
                    break;
                default:
                    break;
            }
            if (!a1) {
                System.out.print("输入0返回主菜单：");
                a = input.nextInt();
            }
        } while (a == 0);
        System.out.println("欢迎下次光临！");
    }
}
